package com.tinyseed.emcp.api.exception.repository;

import com.tinyseed.emcp.api.exception.entity.ExceptionInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;

public interface ExceptionInfoRepository extends JpaRepository<ExceptionInfo, Long>, JpaSpecificationExecutor<ExceptionInfo> {

    @Query(value = "select e from ExceptionInfo e where 1=1 and ( e.createTime between ?4 and ?5) and e.enterpriseName = ?1 and e.eventType = ?2 and e.organizeName = ?3")
    Page<ExceptionInfo> searchByTime(String enterpriseName, String exceptionType, String organizeName, Date startTime, Date endTime, Pageable pageable);

    @Query(value = "select e from ExceptionInfo e where  e.enterpriseName = ?1 and e.eventType = ?2 and e.organizeName = ?3")
    Page<ExceptionInfo> search(String enterpriseName, String eventType, String organizeName, Pageable pageable);

    Boolean existsByJaId(Long id);

    ExceptionInfo findByJaId(Long id);


}
